<?php
   	include_once('class/autoload.php');  
   	include_once 'class/MyPDO.php';
   	$titre="Connexion";
   	$site = new page_base('Acceuil connexion');
   	$site->titre = "connexion USEP";
   //$vretour=0 ;
if(!isset($_COOKIE["PHPSESSID"]))
   	{
    $site->corps = "
    		<h1> Connexion </h1>
<form action'connection1.php' method='post'>

	<label for='login'>login</label>
	<input type='text' name='login' value='' required/>

	<label for='pass'>Mot de passe</label>
	<input type='password' name='pass' value='' required/>

	<input type='submit' value='Se connecter'/>
    	

</form>
	
    		";
 //   $vretour=$vretour+1;
   	}
if(isset($_COOKIE["PHPSESSID"]))
{ 

	$site->corps = "Deja connect�
			 ";
}    

   	if(!empty($_SESSION))
   	{
   		$site->corps = " Vous etes deja connecter !";
   	}
    if(isset($_POST) && isset($_POST['login']) AND isset($_POST['pass'])){
    	
    	$y = $bdd->prepare('SELECT COUNT(*) FROM membres WHERE nom = ?');
    	$y->execute(array($_POST['login']));
    	$x = $y->fetch();
    	if ($x[0] == 0){
    		echo 'Ce login n\'existe pas';
    	}else{
    		$e = $bdd->prepare('SELECT mot_passe FROM membres WHERE nom = ?');
    		$e->execute(array($_POST['login']));
    		$rep = $e->fetch();
    		$salt = "48@!alsd";
    		$passe = $_POST['pass'];
    		$password_crypte = sha1(sha1($passe).$salt);
    		
    
    		if ($password_crypte == $rep['mot_passe']){
    		session_start();
    		$_SESSION['login'] = $_POST['login'];
    		setCookie("login",$_SESSION['login'],time()+3600);
    			echo 'Vous etes connecter';
    		
    		}else{
    			echo 'Mot de passe incorrect';
    		}
    	}
    
    }
    $site->affiche();
   			
?>